/**
 * +----------------------------------------------------------------------
 * | @Author: codeavatar   @Year：2021
 * +----------------------------------------------------------------------
 * | @Email: codeavatar@aliyun.com
 * +----------------------------------------------------------------------
 **/
 const fwutil = {
	 //参考微信设计
	 inputAmount: function(inputval, decimal){
		 let tmpval = '',valarr = [],hasDot=false;
		 inputval = inputval.trim();
		 //一个字符
		 if(inputval.length == 1){
			 if(inputval == '.'){
				tmpval = '0.';
			 }else{
				 tmpval = inputval;
			 }
		 }else if(inputval.length == 2){
			 valarr = inputval.split('');
			 if(valarr[0] == 0 && valarr[1] != '.'){
				 tmpval = valarr[1];
			 }else{
				 tmpval = inputval;
			 }
		 }else{
			 valarr = inputval.split('');
			 //特殊过滤
			 let lastDotIdx = -1;
			 for(let i=0; i<valarr.length;i++){
				if(valarr[0] == '.' || (valarr[0] == '0' && valarr[1] != '.')){
					valarr.shift();
				}
				break;
			 }
			 for(let i=0; i<valarr.length;i++){
			 	if(valarr[i] == '.'){
			 		if(!hasDot){tmpval += valarr[i]; hasDot = true;}
			 	}else{
			 		tmpval += valarr[i];
			 	}
			 }
		 }
		 //限制小数位数
		 let scale = 0; //默认正整数
		 if(typeof decimal != 'undefined'){
			 scale = parseInt(decimal);
			 //过滤负数
			 if(scale < 0) { scale = 0; }
		 }
		 //限制小数
		 if(scale==0){
			 //取正整数
			 if(tmpval.length>0 && -1 != tmpval.indexOf('.')){
				tmpval = tmpval.substr(0,tmpval.indexOf('.'));
			 }
		 }else if(scale > 0){
			 //取小数位数
			 if(-1 != tmpval.indexOf('.')){
				 if((tmpval.length - 1 - tmpval.indexOf('.')) >= scale){
					 tmpval = tmpval.substr(0,tmpval.indexOf('.')+scale+1);
				 }
			 }
		 }
		 return tmpval;
	 },
}
export default fwutil;